<?php

// Classe liaison entre flash et BD MS SQL Zimbabwe
// Fait par Mehdi Guermazi le 5 f�vrier 2010 mguermazi@infoglobe.ca
// Version 1.8
class igdataaccess {
    
    var $odbc_dsn = 'hrrepository_odbc';
    var $odbc_db = 'HRRepository.dbo.';
    var $hashStr = '463320IG6457:';
	var $link;
    
    function main($xml_req){
        
		// Connect to MSSQL
        $this->link = odbc_connect($this->odbc_dsn, '', '');
		
        $xml_req = str_replace("& ", "&amp; ", $xml_req);
		date_default_timezone_set("Africa/Harare");
		$this->xml = new SimpleXMLElement($xml_req);
        $this->init();
		$loginUsed = $this->xml->SecurityContext->UserName;
        //echo $this->xml->asXML;
        if($this->identify()){ // V�rifier l'identit� de l'utilisateur
            switch($this->xml->getName()){ // V�rifier le type de demande XML envoy� par flash
                case 'EnumDataAccessRequest':
                    $xml_resp = $this->getEnumDataAccessResponse();
					//LOG : fetch
					$docFetched = $this->xml->DocumentNumber;
					$this->runStoredProc("EXECUTE ".$this->odbc_db."sp_LogAuditEvent '"
						.str_replace("'", "''", $loginUsed)."', 'fetch', '".str_replace("'", "''", $docFetched)."'");
                    break;
                case 'EnumDataUpdateRequest':
                    if($this->accessLevel()){ // V�rifier les permissions en �dition de l'utilisateur (d�veloppement futur)
                        $xml_resp = $this->getEnumDataUpdateResponse();
                    }
                    else{ // Envoyer une erreur parce que l'utilisateur n'a pas la permission d'�dition (d�veloppement futur)
                        $xml_resp = $this->getErrorResponse('','');
                    }
					//LOG Update
					$this->runStoredProc("EXECUTE ".$this->odbc_db."sp_LogAuditEvent '"
						.str_replace("'", "''", $loginUsed)."', 'update', '".str_replace("'", "''", $xml_req)."'");
                    break;
                case 'ReferenceDataAccessRequest':
                    $xml_resp = $this->getReferenceDataAccessResponse();
					//LOG : Login success
					$this->runStoredProc("EXECUTE ".$this->odbc_db."sp_LogAuditEvent '"
						.str_replace("'", "''", $loginUsed)."', 'login', 'success'");
                    break;
				case 'UnlockDocumentRequest':
					$docFetched = $this->xml->DocumentNumber;
					$this->runStoredProc("EXECUTE ".$this->odbc_db."sp_LogAuditEvent '"
						.str_replace("'", "''", $loginUsed)."', 'unlock', '".str_replace("'", "''", $docFetched)."'");
					$sqlArr['fields']['Rejected'] = "1";
					$sqlArr['tables'] = $this->odbc_db.'RepositoryExt';
					$sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $docFetched)."'";
					$testQuery = $this->updateData($sqlArr);
					if ($testQuery == false) {
						$errorFound = true;
						$errorMsg = odbc_errormsg($this->link);
						return $this->getErrorResponse("99", "Document was not unlocked. Error : $errorMsg");
					}
					$str_resp = '<?xml version="1.0" encoding="utf-8"?>
                        <UnlockDocumentResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ></UnlockDocumentResponse>';
					$xml_resp = new SimpleXMLElement($str_resp);
					
					$xml_resp->addChild('UpdatedRowCount', '1');
					return $xml_resp->asXML();
					break;
                default:
                    break;
            }
        }
        else{ // Envoyer une erreur parce que l'utilisateur n'a pas �t� identifi�
            $xml_resp = $this->getErrorResponse('1','Invalid username / password pair');
			//LOG : Login failure
			$this->runStoredProc("EXECUTE ".$this->odbc_db."sp_LogAuditEvent '"
				.str_replace("'", "''", $loginUsed)."', 'login', 'failure'");
        }
        
		//Fermer connection ODBC
		odbc_close($this->link);
		
        return $xml_resp;
    }
    
    function init(){
        $this->xml->DocumentNumber = (int)($this->xml->DocumentNumber);
        $this->xml->EnumData->DocumentNumber = (int)($this->xml->EnumData->DocumentNumber);
    }

    // Retourne la r�ponse XML � une demande de donn�es
    function getEnumDataAccessResponse(){
		
		if($this->xml->DocumentNumber == 0 || ($this->xml->DocumentNumber >= 800000 && $this->xml->DocumentNumber <= 999999)){
            if ($this->xml->DocumentNumber==0) {
                $row['DocNo'] = $this->runSQL("UPDATE ".$this->odbc_db
					."SequenceTable set NextVal = NextVal + 1 OUTPUT inserted.NextVal where name = 'NextBlankEUID'");
                $newDocNo = $row['DocNo'][0]['NextVal'];
                $this->xml->DocumentNumber = (int)($newDocNo);
                $this->xml->EnumData->DocumentNumber = (int)($newDocNo);
            }
			
			//On doit verifier si la valeur existe deja dans la BD (on n'a pas de cl� primaire)
			$sqlArr['fields'] = '[EUID]';
			$sqlArr['tables'] = $this->odbc_db.'Repository';
			$sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $this->xml->DocumentNumber)."'";
			$testExiste['Repository'] = $this->getData($sqlArr);
			
			if (is_array($testExiste['Repository'])==false) {
				$this->runStoredProc("insert into ".$this->odbc_db."Repository (EUID) values ('"
					.str_replace("'", "''", $this->xml->DocumentNumber)."');");
			}
        }

        // Chercher les donn�es dans la base de donn�es
        
        if(!$this->xml->DocumentNumber){
			return $this->getErrorResponse('2','No Repository Found');
		}
        
		try {
			$sqlArr['fields'] = '[EUID],[MinistryID],[ECNo],[NID],[Salutation],[FirstName],[MiddleName],[Surname],[DOB]'
				.',[DOFA],[DOAPG],[TOE],[Department],[Station],[SalaryCode],[TotalGrossSalary],[Designation],[Grade]'
				.',[Qualifications],[Street],[POBox],[Suburb],[Area],[City],[Province],[Allowance1Desc],[Allowance1Amt]'
				.',[Allowance2Desc],[Allowance2Amt],[Allowance3Desc],[Allowance3Amt],[RowCreationDate],[RowUpdatedDate]';
			$sqlArr['tables'] = $this->odbc_db.'Repository';
            $sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $this->xml->DocumentNumber)."'";
			$row['Repository'] = $this->getData($sqlArr);
            
            $sqlArr['fields'] = '[EUID],[TransactionType],[AttendanceID],[EnumerationDate],[EnumerationName]'
				.',[EnumerationSignature],[PreviousName],[NSSAID],[BirthEntryNo],[MedicalAidId],[AuthChangeName]'
				.',[DOBCheckbox],[POB],[POBCheckbox],[CityCheckbox],[District],[DistrictCheckbox],[ProvinceCheckbox]'
				.',[Country],[CountryCheckbox],[Sex],[SexCheckbox],[MaritalStatus],[MaritalStatusCheckbox],[Nationality]'
				.',[NationalityCheckbox],[DocUsedForVerif],[HomePhone],[WorkPhone],[MobilePhone],[DOFACheckbox]'
				.',[ApptLetterDate],[ApptLetterDateCheckbox],[DateReappt],[DateReapptCheckbox],[DOAPGCheckbox]'
				.',[DesignationCheckbox],[GradeCheckbox],[SalaryCodeCheckbox],[TotalGrossSalaryCheckbox]'
				.',[MedicalClearanceFormDate],[MedicalClearanceFormDateCheckbox],[PoliceClearanceFormDate]'
				.',[PoliceClearanceFormDateCheckbox],[ApptFormDate],[ApptFormDateCheckbox],[PassportCopyBox]'
				.',[ApptLetterCopyBox],[MedicalClearFormCopyBox],[BirthCertifCopyBox],[ApptFormCopyBox]'
				.',[PoliceClearFormCopyBox],[RespondentSign],[AuditorName],[AuditorSign],[DataEnteryUserName]'
				.',[DataEnteryUserSign],[ObserverSign],[ObserverName],[DateObservations],[OpinionGiverSign]'
				.',[OpinionGiverName],[DataEntryDate],[DataVerificationUserName],[DataVerificationUserSign],[StatusCode]'
				.',[DataVerificationDate],[DateOpinionGiven],[Address],[ContactProvince],[ContactCity],[ContactDistrict],'
				.'[Rejected],[VerifierComment],[RowCreationDate],[RowUpdatedDate]';
			$sqlArr['tables'] = $this->odbc_db.'RepositoryExt';
            //Where identique
			$row['RepositoryExt'] = $this->getData($sqlArr);

            $sqlArr['fields'] = '[ID],[InstitutionTypeId],[InstitutionName],[FieldId],[QualificationId],[YearCompleted],[DocumentsName]'
				.',[DocumentsBox]';
			$sqlArr['tables'] = $this->odbc_db.'AcademicQualif';
            //Where identique
			$row['AcademicQualif'] = $this->getData($sqlArr);

            $sqlArr['fields'] = '[ID],[Field],[qualification],[InstitutionName],[YearCompleted],[DocumentsName],[DocumentsBox]';
			$sqlArr['tables'] = $this->odbc_db.'UniversityQualif';
            //Where identique
			$row['UniversityQualif'] = $this->getData($sqlArr);
            
            $sqlArr['fields'] = '[ID],[Field],[qualification],[InstitutionName],[YearCompleted],[DocumentsName],[DocumentsBox]';
			$sqlArr['tables'] = $this->odbc_db.'ProfQualif';
            //Where identique
			$row['ProfQualif'] = $this->getData($sqlArr);
            
            $sqlArr['fields'] = '[ID],[Course],[Institution],[YearCompleted],[DocumentsName],[DocumentsBox]';
			$sqlArr['tables'] = $this->odbc_db.'Training';
            //Where identique
			$row['Training'] = $this->getData($sqlArr);
            
            $sqlArr['fields'] = '[DocumentSection],[NoteRef],[Observation],[Opinion]';
			$sqlArr['tables'] = $this->odbc_db.'Notes';
            //Where identique
			$row['Notes'] = $this->getData($sqlArr);

            /*$sqlArr['fields'] = 'description';
			$sqlArr['tables'] = $this->odbc_db.'ComboListSeedData';
            $sqlArr['where'] = "ComboList = 'AcademicInstitutions' order by description";
            $row['AcadInstitutions'] = $this->getData($sqlArr);*/

            //Field identique
			/*$sqlArr['tables'] = $this->odbc_db.'ComboListSeedData';
            $sqlArr['where'] = "ComboList = 'UniversityInstitutions' order by description";
            $row['UnivInstituts'] = $this->getData($sqlArr);*/

            //Field identique
			/*$sqlArr['tables'] = $this->odbc_db.'ComboListSeedData';
            $sqlArr['where'] = "ComboList = 'UniversityFields' order by description";
            $row['UnivFields'] = $this->getData($sqlArr);*/

            $sqlArr['fields'] = 'description';
			$sqlArr['tables'] = $this->odbc_db.'ComboListSeedData';
            $sqlArr['where'] = "ComboList = 'UniversityQualifications' order by description";
            $row['UnivQuals'] = $this->getData($sqlArr);

            //Field identique
			/*$sqlArr['tables'] = $this->odbc_db.'ComboListSeedData';
            $sqlArr['where'] = "ComboList = 'ProfessionalInstitutions' order by description";
            $row['ProfInstituts'] = $this->getData($sqlArr);*/

            //Field identique
			/*$sqlArr['tables'] = $this->odbc_db.'ComboListSeedData';
            $sqlArr['where'] = "ComboList = 'ProfessionalFields' order by description";
            $row['ProfFields'] = $this->getData($sqlArr);*/

            $sqlArr['fields'] = 'description';
			$sqlArr['tables'] = $this->odbc_db.'ComboListSeedData';
            $sqlArr['where'] = "ComboList = 'ProfessionalQualifications' order by description";
            $row['ProfQuals'] = $this->getData($sqlArr);

            //Field identique
			/*$sqlArr['tables'] = $this->odbc_db.'ComboListSeedData';
            $sqlArr['where'] = "ComboList = 'TrainingInstitutions' order by description";
            $row['TrainingInstituts'] = $this->getData($sqlArr);*/

            //Field identique
            /*$sqlArr['tables'] = $this->odbc_db.'ComboListSeedData';
            $sqlArr['where'] = "ComboList = 'TrainingCourses' order by description";
            $row['TrainingCourses'] = $this->getData($sqlArr);*/
        } catch (Exception $e) {
			return $this->getErrorResponse('98','Error while fetching : $e');
		}
        
		// Cr�er l'XML � partir des donn�es pris dans la base de donn�es
        
        $str_resp = '<?xml version="1.0" encoding="utf-8"?>
                        <EnumDataAccessResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ></EnumDataAccessResponse>';
        
        $xml_resp = new SimpleXMLElement($str_resp);
        
        $xml_resp->addChild('EnumData');
        $xml_resp->EnumData->addChild('DocumentNumber',$this->xml->DocumentNumber);
        if (isset($row['RepositoryExt'][0])) {
			$xml_resp->EnumData->addChild('TransactionType', $row['RepositoryExt'][0]['TransactionType']);
		}
        
        $xml_resp->EnumData->addChild('StationID');
        
		if (isset($row['Repository'][0])) {
			$xml_resp->EnumData->StationID->addChild('MinistryId', str_replace("& ", "&amp; ", $row['Repository'][0]['MinistryID']));
		}
		if(isset($row['Repository'][0]['MinistryID'])){
			$sqlArr['fields'] = 'MinistryDesc';
            $sqlArr['tables'] = $this->odbc_db.'Ministries';
            $sqlArr['where'] = '[MinistryID] = '.str_replace("'", "''", $row['Repository'][0]['MinistryID']);
            $row['Ministries'] = $this->getData($sqlArr);
			$xml_resp->EnumData->StationID->addChild('MinistryName', str_replace("&", "&amp;", $row['Ministries'][0]['MinistryDesc']));
        } else {
			$xml_resp->EnumData->StationID->addChild('MinistryName');
		}
        
        if (isset($row['Repository'][0])) {
			$xml_resp->EnumData->StationID->addChild('DepartmentId', str_replace("& ", "&amp; ", $row['Repository'][0]['Department']));
		}
		if(isset($row['Repository'][0]['Department'])){
			$sqlArr['fields'] = 'DepartmentDesc';
            $sqlArr['tables'] = $this->odbc_db.'Departments';
            $sqlArr['where'] = '[DepartmentCode] = '.str_replace("'", "''", $row['Repository'][0]['Department']);
            $row['Departments'] = $this->getData($sqlArr);
			$xml_resp->EnumData->StationID->addChild('DepartmentName', str_replace("&", "&amp;", $row['Departments'][0]['DepartmentDesc']));
        } else {
			$xml_resp->EnumData->StationID->addChild('DepartmentName');
		}
        
		if (isset($row['Repository'][0])) {
			$xml_resp->EnumData->StationID->addChild('PayStationId', str_replace("& ", "&amp; ", $row['Repository'][0]['Station']));
		}
		if(isset($row['Repository'][0]['Station']) && isset($row['Repository'][0]['MinistryID']) && isset($row['Repository'][0]['Department'])){
            $sqlArr['fields'] = 'ProvinceCode, DistrictCode, PayStationDesc';
			$sqlArr['tables'] = $this->odbc_db.'PayStations';
            $sqlArr['where'] = '[PayStationCode] = '.str_replace("'", "''", $row['Repository'][0]['Station']);
            $sqlArr['where'] .= ' AND [MinistryID] = '.str_replace("'", "''", $row['Repository'][0]['MinistryID']);
            $sqlArr['where'] .= ' AND [DeptCode] = '.str_replace("'", "''", $row['Repository'][0]['Department']);
            $row['PayStations'] = $this->getData($sqlArr);
			$xml_resp->EnumData->StationID->addChild('ProvinceId', $row['PayStations'][0]['ProvinceCode']);
			$xml_resp->EnumData->StationID->addChild('DistrictId', $row['PayStations'][0]['DistrictCode']);
			$xml_resp->EnumData->StationID->addChild('PayStationName', str_replace("&", "&amp;", $row['PayStations'][0]['PayStationDesc']));

			if($row['PayStations'][0]['DistrictCode']){
				$sqlArr['fields'] = 'DistrictName';
				$sqlArr['tables'] = $this->odbc_db.'Districts';
				$sqlArr['where'] = '[DistrictCode] = '.str_replace("'", "''", $row['PayStations'][0]['DistrictCode']);
				$row['Districts'] = $this->getData($sqlArr);
				$xml_resp->EnumData->StationID->addChild('District', str_replace("&", "&amp;", $row['Districts'][0]['DistrictName']));
			} else {
				$xml_resp->EnumData->StationID->addChild('District');
			}
        } else {
			$xml_resp->EnumData->StationID->addChild('ProvinceId');
			$xml_resp->EnumData->StationID->addChild('DistrictId');
			$xml_resp->EnumData->StationID->addChild('PayStationName');
		}

        if (isset($row['RepositoryExt'][0])) {
			$xml_resp->EnumData->StationID->addChild('Attendance', $row['RepositoryExt'][0]['AttendanceID']);
			$xml_resp->EnumData->StationID->addChild('EnumerationDate',
				$row['RepositoryExt'][0]['EnumerationDate']?date('c', strtotime($row['RepositoryExt'][0]['EnumerationDate'])):'' );
			$xml_resp->EnumData->StationID->addChild('EnumerationName', $row['RepositoryExt'][0]['EnumerationName']);
			$xml_resp->EnumData->StationID->addChild('EnumerationSign', $row['RepositoryExt'][0]['EnumerationSignature']);
		}
        
        $xml_resp->EnumData->addChild('PersonnelID');
        if (isset($row['Repository'][0])) {
			$xml_resp->EnumData->PersonnelID->addChild('Title', str_replace("& ", "&amp; ", $row['Repository'][0]['Salutation']));
			$xml_resp->EnumData->PersonnelID->addChild('Surname', str_replace("& ", "&amp; ", $row['Repository'][0]['Surname']));
			$xml_resp->EnumData->PersonnelID->addChild('FirstName', str_replace("& ", "&amp; ", $row['Repository'][0]['FirstName']));
			$xml_resp->EnumData->PersonnelID->addChild('OtherNames', str_replace("& ", "&amp; ", $row['Repository'][0]['MiddleName']));
			$xml_resp->EnumData->PersonnelID->addChild('NationalId', str_replace("& ", "&amp; ", $row['Repository'][0]['NID']));
			$xml_resp->EnumData->PersonnelID->addChild('ECNumber', str_replace("& ", "&amp; ", $row['Repository'][0]['ECNo']));
		}
		if (isset($row['RepositoryExt'][0])) {
			$xml_resp->EnumData->PersonnelID->addChild('PreviousName', $row['RepositoryExt'][0]['PreviousName']);
			$xml_resp->EnumData->PersonnelID->addChild('NSSAId', $row['RepositoryExt'][0]['NSSAID']);
			$xml_resp->EnumData->PersonnelID->addChild('BirthEntryNo', $row['RepositoryExt'][0]['BirthEntryNo']);
			$xml_resp->EnumData->PersonnelID->addChild('MedicalAidId', $row['RepositoryExt'][0]['MedicalAidId']);
			$xml_resp->EnumData->PersonnelID->addChild('Authorization', $row['RepositoryExt'][0]['AuthChangeName']);
		}
        
        $xml_resp->EnumData->addChild('PersonalInfo');
        if (isset($row['Repository'][0])) {
			$xml_resp->EnumData->PersonalInfo->addChild('DateBirth',
				$row['Repository'][0]['DOB']?date('c', strtotime($row['Repository'][0]['DOB'])):'');
			$xml_resp->EnumData->PersonalInfo->addChild('Province', str_replace("& ", "&amp; ", $row['Repository'][0]['Province']));
			$xml_resp->EnumData->PersonalInfo->addChild('City', str_replace("& ", "&amp; ", $row['Repository'][0]['City']));
		}
		if (isset($row['RepositoryExt'][0])) {
			$xml_resp->EnumData->PersonalInfo->addChild('DateBirthCheckbox', $row['RepositoryExt'][0]['DOBCheckbox']);
			$xml_resp->EnumData->PersonalInfo->addChild('PlaceBirth', $row['RepositoryExt'][0]['POB']);
			$xml_resp->EnumData->PersonalInfo->addChild('PlaceBirthCheckbox', $row['RepositoryExt'][0]['POBCheckbox']);
			$xml_resp->EnumData->PersonalInfo->addChild('CityCheckbox', $row['RepositoryExt'][0]['CityCheckbox']);
			$xml_resp->EnumData->PersonalInfo->addChild('District', $row['RepositoryExt'][0]['District']);
			$xml_resp->EnumData->PersonalInfo->addChild('DistrictCheckbox', $row['RepositoryExt'][0]['DistrictCheckbox']);
			$xml_resp->EnumData->PersonalInfo->addChild('ProvinceCheckbox', $row['RepositoryExt'][0]['ProvinceCheckbox']);
			$xml_resp->EnumData->PersonalInfo->addChild('Country', $row['RepositoryExt'][0]['Country']);
			$xml_resp->EnumData->PersonalInfo->addChild('CountryCheckbox', $row['RepositoryExt'][0]['CountryCheckbox']);
			$xml_resp->EnumData->PersonalInfo->addChild('Sex', $row['RepositoryExt'][0]['Sex']);
			$xml_resp->EnumData->PersonalInfo->addChild('SexCheckbox', $row['RepositoryExt'][0]['SexCheckbox']);
			$xml_resp->EnumData->PersonalInfo->addChild('MaritalStatus', $row['RepositoryExt'][0]['MaritalStatus']);
			$xml_resp->EnumData->PersonalInfo->addChild('MaritalStatusCheckbox', $row['RepositoryExt'][0]['MaritalStatusCheckbox']);
			$xml_resp->EnumData->PersonalInfo->addChild('Nationality', $row['RepositoryExt'][0]['Nationality']);
			$xml_resp->EnumData->PersonalInfo->addChild('NationalityCheckbox', $row['RepositoryExt'][0]['NationalityCheckbox']);
			$xml_resp->EnumData->PersonalInfo->addChild('DocumentUsed', $row['RepositoryExt'][0]['DocUsedForVerif']);
		}
        
        $xml_resp->EnumData->addChild('ContactInfo');
        //Modified for new fields
        if (isset($row['RepositoryExt'][0])) {
			$xml_resp->EnumData->ContactInfo->addChild('Address', $row['RepositoryExt'][0]['Address']);
			$xml_resp->EnumData->ContactInfo->addChild('ContactCity', $row['RepositoryExt'][0]['ContactCity']);
			$xml_resp->EnumData->ContactInfo->addChild('ContactDistrict', $row['RepositoryExt'][0]['ContactDistrict']);
			$xml_resp->EnumData->ContactInfo->addChild('ContactProvince', $row['RepositoryExt'][0]['ContactProvince']);
			$xml_resp->EnumData->ContactInfo->addChild('HomePhone', $row['RepositoryExt'][0]['HomePhone']);
			$xml_resp->EnumData->ContactInfo->addChild('WorkPhone', $row['RepositoryExt'][0]['WorkPhone']);
			$xml_resp->EnumData->ContactInfo->addChild('MobilePhone', $row['RepositoryExt'][0]['MobilePhone']);
		}
        
        $xml_resp->EnumData->addChild('RecordOfEmployment');
        if (isset($row['Repository'][0])) {
			$xml_resp->EnumData->RecordOfEmployment->addChild('DateFirstAppt',
				$row['Repository'][0]['DOFA']?date('c', strtotime($row['Repository'][0]['DOFA'])):'');
			$xml_resp->EnumData->RecordOfEmployment->addChild('GrossMonthSalary', $row['Repository'][0]['TotalGrossSalary']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('SalaryCode', str_replace("& ", "&amp; ", $row['Repository'][0]['SalaryCode']));
			$xml_resp->EnumData->RecordOfEmployment->addChild('CurrentGrade', str_replace("& ", "&amp; ", $row['Repository'][0]['Grade']));
			$xml_resp->EnumData->RecordOfEmployment->addChild('Designation', str_replace("& ", "&amp; ", $row['Repository'][0]['Designation']));
			$xml_resp->EnumData->RecordOfEmployment->addChild('DateApptCurr',
			$row['Repository'][0]['DOAPG']?date('c', strtotime($row['Repository'][0]['DOAPG'])):'');
		}
		if (isset($row['RepositoryExt'][0])) {
			$xml_resp->EnumData->RecordOfEmployment->addChild('DateFirstApptCheckbox', $row['RepositoryExt'][0]['DOFACheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('ApptLetterDate',
				$row['RepositoryExt'][0]['ApptLetterDate']?date('c', strtotime($row['RepositoryExt'][0]['ApptLetterDate'])):'');
			$xml_resp->EnumData->RecordOfEmployment->addChild('ApptLetterDateCheckbox', $row['RepositoryExt'][0]['ApptLetterDateCheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('DateReappt',
				$row['RepositoryExt'][0]['DateReappt']?date('c', strtotime($row['RepositoryExt'][0]['DateReappt'])):'');
			$xml_resp->EnumData->RecordOfEmployment->addChild('DateReapptCheckbox', $row['RepositoryExt'][0]['DateReapptCheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('DateApptCurrCheckbox', $row['RepositoryExt'][0]['DOAPGCheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('DesignationCheckbox', $row['RepositoryExt'][0]['DesignationCheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('CurrentGradeCheckbox', $row['RepositoryExt'][0]['GradeCheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('SalaryCodeCheckbox', $row['RepositoryExt'][0]['SalaryCodeCheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('GrossMonthSalaryCheckbox', $row['RepositoryExt'][0]['TotalGrossSalaryCheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('MedicalClearFormDate',
				$row['RepositoryExt'][0]['MedicalClearanceFormDate']?date('c', strtotime($row['RepositoryExt'][0]['MedicalClearanceFormDate'])):'');
			$xml_resp->EnumData->RecordOfEmployment->addChild('MedicalClearFormDateCheckbox',
				$row['RepositoryExt'][0]['MedicalClearanceFormDateCheckbo']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('PoliceClearFormDate',
				$row['RepositoryExt'][0]['PoliceClearanceFormDate']?date('c', strtotime($row['RepositoryExt'][0]['PoliceClearanceFormDate'])):'');
			$xml_resp->EnumData->RecordOfEmployment->addChild('PoliceClearFormDateCheckbox',
				$row['RepositoryExt'][0]['PoliceClearanceFormDateCheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('AppointmentFormDate',
				$row['RepositoryExt'][0]['ApptFormDate']?date('c', strtotime($row['RepositoryExt'][0]['ApptFormDate'])):'');
			$xml_resp->EnumData->RecordOfEmployment->addChild('ApptFormDateCheckbox', $row['RepositoryExt'][0]['ApptFormDateCheckbox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('Passport', $row['RepositoryExt'][0]['PassportCopyBox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('AppointmentLetter', $row['RepositoryExt'][0]['ApptLetterCopyBox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('MedicalClearForm', $row['RepositoryExt'][0]['MedicalClearFormCopyBox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('BirthCertificate', $row['RepositoryExt'][0]['BirthCertifCopyBox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('AppointmentForm', $row['RepositoryExt'][0]['ApptFormCopyBox']);
			$xml_resp->EnumData->RecordOfEmployment->addChild('PoliceClearForm', $row['RepositoryExt'][0]['PoliceClearFormCopyBox']);
		}
        
        //print_r($row['RepositoryExt']);
        
        if(isset($row['AcademicQualif'])){
            foreach($row['AcademicQualif'] as $key => $value){
                $academicQual = $xml_resp->EnumData->addChild('AcademicQual');
                $academicQual->addChild('InstitutionTypeId', $value['InstitutionTypeId']);
                $academicQual->addChild('InstitutionName', $value['InstitutionName']);
                $academicQual->addChild('FieldId', $value['FieldId']);
                $academicQual->addChild('QualificationId', $value['QualificationId']);
                $academicQual->addChild('YearCompleted', $value['YearCompleted']);
                $academicQual->addChild('DocumentName', $value['DocumentsName']);
                $academicQual->addChild('DocumentState', $value['DocumentsBox']);
				$academicQual->addChild('id', $value['ID']);
            }
        }

        /*$xml_resp->addChild('AcadInstitutions');
        if(isset($row['AcadInstitutions'])){
            foreach($row['AcadInstitutions'] as $key => $value){
                $xml_resp->AcadInstitutions->addChild('Name', $value['description']);
            }
        }*/

        if(isset($row['UniversityQualif'])){
            foreach($row['UniversityQualif'] as $key => $value){
                $universityQual = $xml_resp->EnumData->addChild('UniversityQual');
                $universityQual->addChild('InstitutionName', $value['InstitutionName']);
                $universityQual->addChild('Field', $value['Field']);
                $universityQual->addChild('Qualification', $value['qualification']);
                $universityQual->addChild('YearCompleted', $value['YearCompleted']);
                $universityQual->addChild('DocumentName', $value['DocumentsName']);
                $universityQual->addChild('DocumentState', $value['DocumentsBox']);
				$universityQual->addChild('id', $value['ID']);
            }
        }

        /*$xml_resp->addChild('UnivInstituts');
        if(isset($row['UnivInstituts'])){
            foreach($row['UnivInstituts'] as $key => $value){
                $xml_resp->UnivInstituts->addChild('Name', $value['description']);
            }
        }*/

        /*$xml_resp->addChild('UnivFields');
        if(isset($row['UnivFields'])){
            foreach($row['UnivFields'] as $key => $value){
                $xml_resp->UnivFields->addChild('Name', str_replace("& ", "&amp; ", $value['description']));
            }
        }*/

        $xml_resp->addChild('UnivQuals');
        if(isset($row['UnivQuals'])){
            foreach($row['UnivQuals'] as $key => $value){
                $xml_resp->UnivQuals->addChild('Name', str_replace("& ", "&amp; ", $value['description']));
            }
        }

        if(isset($row['ProfQualif'])){
            foreach($row['ProfQualif'] as $key => $value){
                $profQual = $xml_resp->EnumData->addChild('ProfQual');
                $profQual->addChild('InstitutionName', $value['InstitutionName']);
                $profQual->addChild('Field', $value['Field']);
                $profQual->addChild('Qualification', $value['qualification']);
                $profQual->addChild('YearCompleted', $value['YearCompleted']);
                $profQual->addChild('DocumentName', $value['DocumentsName']);
                $profQual->addChild('DocumentState', $value['DocumentsBox']);
				$profQual->addChild('id', $value['ID']);
            }
        }

        /*$xml_resp->addChild('ProfInstituts');
        if(isset($row['ProfInstituts'])){
            foreach($row['ProfInstituts'] as $key => $value){
                $xml_resp->ProfInstituts->addChild('Name', $value['description']);
            }
        }*/

        /*$xml_resp->addChild('ProfFields');
        if(isset($row['ProfFields'])){
            foreach($row['ProfFields'] as $key => $value){
                $xml_resp->ProfFields->addChild('Name', str_replace("& ", "&amp; ", $value['description']));
            }
        }*/

        $xml_resp->addChild('ProfQuals');
        if(isset($row['ProfQuals'])){
            foreach($row['ProfQuals'] as $key => $value){
                $xml_resp->ProfQuals->addChild('Name', str_replace("& ", "&amp; ", $value['description']));
            }
        }
        
        if(isset($row['Training'])){
            foreach($row['Training'] as $key => $value){
                $inServiceTraining = $xml_resp->EnumData->addChild('InServiceTraining');
                $inServiceTraining->addChild('TrainingCourse', $value['Course']);
                $inServiceTraining->addChild('Institution', $value['Institution']);
                $inServiceTraining->addChild('YearCompleted', $value['YearCompleted']);
                $inServiceTraining->addChild('DocumentName', $value['DocumentsName']);
                $inServiceTraining->addChild('DocumentState', $value['DocumentsBox']);
				$inServiceTraining->addChild('id', $value['ID']);
            }
        }

        /*$xml_resp->addChild('TrainingInstituts');
        if(isset($row['TrainingInstituts'])){
            foreach($row['TrainingInstituts'] as $key => $value){
                $xml_resp->TrainingInstituts->addChild('Name', $value['description']);
            }
        }*/

        /*$xml_resp->addChild('TrainingCourses');
        if(isset($row['TrainingCourses'])){
            foreach($row['TrainingCourses'] as $key => $value){
                $xml_resp->TrainingCourses->addChild('Name', $value['description']);
            }
        }*/

        if(isset($row['Notes'])){
            $xml_resp->EnumData->addChild('Notes');
            foreach($row['Notes'] as $key => $value){
                $note = $xml_resp->EnumData->Notes->addChild('Note');
                $note->addChild('RelatedSection', $value['DocumentSection']);
                $note->addChild('NoteRef', $value['NoteRef']);
                $note->addChild('Observation', $value['Observation']);
                $note->addChild('Opinion', $value['Opinion']);
            }
            $xml_resp->EnumData->Notes->addChild('DateObservations',
				$row['RepositoryExt'][0]['DateObservations']?date('c', strtotime($row['RepositoryExt'][0]['DateObservations'])):'');
            $xml_resp->EnumData->Notes->addChild('ObserverName', $row['RepositoryExt'][0]['ObserverName']);
            $xml_resp->EnumData->Notes->addChild('ObserverSign', $row['RepositoryExt'][0]['ObserverSign']);
            $xml_resp->EnumData->Notes->addChild('DateOpinionGiven',
				$row['RepositoryExt'][0]['DateOpinionGiven']?date('c', strtotime($row['RepositoryExt'][0]['DateOpinionGiven'])):'');
            $xml_resp->EnumData->Notes->addChild('OpinionGiverName', $row['RepositoryExt'][0]['OpinionGiverName']);
            $xml_resp->EnumData->Notes->addChild('OpinionGiverSign', $row['RepositoryExt'][0]['OpinionGiverSign']);
        }
        
        if (isset($row['RepositoryExt'][0])) {
			$xml_resp->EnumData->addChild('RespondentSign', $row['RepositoryExt'][0]['RespondentSign']);
			$xml_resp->EnumData->addChild('AuditorName', $row['RepositoryExt'][0]['AuditorName']);
			$xml_resp->EnumData->addChild('AuditorSign', $row['RepositoryExt'][0]['AuditorSign']);
			$xml_resp->EnumData->addChild('DataEntryUserName', $row['RepositoryExt'][0]['DataEnteryUserName']);
			$xml_resp->EnumData->addChild('DataEntryUserSign', $row['RepositoryExt'][0]['DataEnteryUserSign']);
			$xml_resp->EnumData->addChild('DataEntryDate',
				$row['RepositoryExt'][0]['DataEntryDate']?date('c', strtotime($row['RepositoryExt'][0]['DataEntryDate'])):'');
			$xml_resp->EnumData->addChild('DataVerificationUserName', $row['RepositoryExt'][0]['DataVerificationUserName']);
			$xml_resp->EnumData->addChild('DataVerificationUserSign', $row['RepositoryExt'][0]['DataVerificationUserSign']);
			$xml_resp->EnumData->addChild('DataVerificationDate',
				$row['RepositoryExt'][0]['DataVerificationDate']?date('c', strtotime($row['RepositoryExt'][0]['DataVerificationDate'])):'');
			$xml_resp->EnumData->addChild('StatusCode', $row['RepositoryExt'][0]['StatusCode']);
			$xml_resp->EnumData->addChild('Rejected', $row['RepositoryExt'][0]['Rejected']);
			$xml_resp->EnumData->addChild('VerifierComment', $row['RepositoryExt'][0]['VerifierComment']);
		}
        
        // V�rifie si il existe un Repository avec l'identifiant re�u et envoyer une erreur si il n'existe pas
        if(isset($row['Repository'])){
            $xml = $xml_resp->asXML();
        }
        else{
            $xml = $this->getErrorResponse('2','No Repository Found');
        }
        
        return $xml;
    }
    
    function getEnumDataUpdateResponse(){
        $str_resp = '<?xml version="1.0" encoding="utf-8"?>
                        <EnumDataUpdateResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ></EnumDataUpdateResponse>';
        
        $xml_resp = new SimpleXMLElement($str_resp);
        
        $updatedRowCount = $this->updateXmlData();
			$xml_resp->addChild('UpdatedRowCount', $updatedRowCount);
        if ($updatedRowCount != "1") {
			return $this->getErrorResponse("99", "Document was not saved. Error : $updatedRowCount");
		}
		
        return $xml_resp->asXML();
    }
    
    function getReferenceDataAccessResponse(){

		// Chercher les donn�es dans la base de donn�es
        
        $sqlArr['fields'] = '[DataSourceID],[DataSourceDesc]';
		$sqlArr['tables'] = $this->odbc_db.'DataSources';
		$sqlArr['where'] = '';
        $row['DataSources'] = $this->getData($sqlArr);
        
        $sqlArr['fields'] = '[DepartmentCode],[DepartmentDesc]';
		$sqlArr['tables'] = $this->odbc_db.'Departments';
        //Where identique
		$row['Departments'] = $this->getData($sqlArr);
        
        $sqlArr['fields'] = '[DistrictCode],[DistrictName],[ProvinceCode]';
		$sqlArr['tables'] = $this->odbc_db.'Districts';
        //Where identique
		$row['Districts'] = $this->getData($sqlArr);
        
        $sqlArr['fields'] = '[MinistryID],[MinistryDesc]';
		$sqlArr['tables'] = $this->odbc_db.'Ministries';
        //Where identique
		$row['Ministries'] = $this->getData($sqlArr);
        
        $sqlArr['fields'] = '[ID],[MinistryID],[Ministry],[SSBMinistryID],[SSBMinistry]';
		$sqlArr['tables'] = $this->odbc_db.'MinistryCodeMap';
        //Where identique
		$row['MinistryCodeMap'] = $this->getData($sqlArr);
        
        $sqlArr['fields'] = '[MinistryID],[DeptCode],[PayStationCode],[PayStationDesc],[RegionCode],[ProvinceCode],[DistrictCode]';
		$sqlArr['tables'] = $this->odbc_db.'PayStations';
        //Where identique
		$row['PayStations'] = $this->getData($sqlArr);
        
        $sqlArr['fields'] = '[ProvinceCode],[ProvinceName]';
		$sqlArr['tables'] = $this->odbc_db.'Provinces';
        //Where identique
		$row['Provinces'] = $this->getData($sqlArr);
        
        $sqlArr['fields'] = '[RegionCode],[RegionName]';
		$sqlArr['tables'] = $this->odbc_db.'Regions';
        //Where identique
		$row['Regions'] = $this->getData($sqlArr);
        
        $sqlArr['fields'] = '[TOEID],[TOEDesc]';
		$sqlArr['tables'] = $this->odbc_db.'TOECode';
        //Where identique
		$row['TOECode'] = $this->getData($sqlArr);
        
        $sqlArr['fields'] = '[SSBMinistryID],[SSBMinistry]';
		$sqlArr['tables'] = $this->odbc_db.'SSBMinistryCodes';
        //Where identique
		$row['SSBMinistryCodes'] = $this->getData($sqlArr);

        $sqlArr['fields'] = 'ISO, CountryName';
		$sqlArr['tables'] = $this->odbc_db.'Countries';
        //Where identique
		$row['Countries'] = $this->getData($sqlArr);

        $sqlArr['fields'] = 'InstitutionTypeId, Description';
		$sqlArr['tables'] = $this->odbc_db.'InstitutionType';
        $sqlArr['where'] = "Category = 'Academic' ";
        $row['InstitutionsTypes'] = $this->getData($sqlArr);

        $sqlArr['fields'] = 'FieldId, Description';
		$sqlArr['tables'] = $this->odbc_db.'Fields';
        $sqlArr['where'] = "Category='Academic' ";
        $row['AcadFields'] = $this->getData($sqlArr);

        $sqlArr['fields'] = 'fq.FieldId, q.QualificationId, q.Description';
		$sqlArr['tables'] = $this->odbc_db.'FieldQualifications fq join '.$this->odbc_db
			.'Qualifications q on fq.QualificationId = q.QualificationId';
        $row['Qualifications'] = $this->getData($sqlArr);

        $sqlArr['fields'] = 'AccessLevel';
        $sqlArr['tables'] = $this->odbc_db.'Users';
        $sqlArr['where'] = "[Username]='".str_replace("'", "''", $this->xml->SecurityContext->UserName)."'";
        $row['User'] = $this->getData($sqlArr);
        
        
        $str_resp = '<?xml version="1.0" encoding="utf-8"?>
                        <ReferenceDataAccessResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
						</ReferenceDataAccessResponse>';
        
        $xml_resp = new SimpleXMLElement($str_resp);
        
        $xml_resp->addChild('DataSources');
        if(is_array($row['DataSources'])){
            foreach($row['DataSources'] as $key => $value){
                $DataSource = $xml_resp->DataSources->addChild('DataSource');
                $DataSource->addChild('DataSourceID', $value['DataSourceID']);
                $DataSource->addChild('DataSourceDesc', str_replace("&", "&amp;", $value['DataSourceDesc']) );
            }
        }
        
        $xml_resp->addChild('Departments');
        if(is_array($row['Departments'])){
            foreach($row['Departments'] as $key => $value){
                $Department = $xml_resp->Departments->addChild('Department');
                $Department->addChild('DepartmentCode', $value['DepartmentCode'] );
                $Department->addChild('DepartmentDesc', str_replace("&", "&amp;", $value['DepartmentDesc']) );
            }
        }
        
        $xml_resp->addChild('Districts');
        if(is_array($row['Districts'])){
            foreach($row['Districts'] as $key => $value){
                $District = $xml_resp->Districts->addChild('District');
                $District->addChild('DistrictCode', $value['DistrictCode'] );
                $District->addChild('DistrictName', str_replace("&", "&amp;", $value['DistrictName']) );
                $District->addChild('ProvinceCode', $value['ProvinceCode'] );
            }
        }
        
        $xml_resp->addChild('Ministries');
        if(is_array($row['Ministries'])){
            foreach($row['Ministries'] as $key => $value){
                $Ministry = $xml_resp->Ministries->addChild('Ministry');
                $Ministry->addChild('MinistryID', $value['MinistryID'] );
                $Ministry->addChild('MinistryDesc', str_replace("&", "&amp;", $value['MinistryDesc']) );
            }
        }
        
        $xml_resp->addChild('Provinces');
        if(is_array($row['Provinces'])){
            foreach($row['Provinces'] as $key => $value){
                $Province = $xml_resp->Provinces->addChild('Province');
                $Province->addChild('ProvinceCode', $value['ProvinceCode'] );
                $Province->addChild('ProvinceName', str_replace("&", "&amp;", $value['ProvinceName']) );
            }
        }
        
        $xml_resp->addChild('Regions');
        if(is_array($row['Regions'])){
            foreach($row['Regions'] as $key => $value){
                $Region = $xml_resp->Regions->addChild('Region');
                $Region->addChild('RegionCode', $value['RegionCode'] );
                $Region->addChild('RegionName', str_replace("&", "&amp;", $value['RegionName']) );
            }
        }
        
        /*$xml_resp->addChild('SSBMinistryCodes');
        if(is_array($row['SSBMinistryCodes'])){
            foreach($row['SSBMinistryCodes'] as $key => $value){
                $SSBMinistryCode = $xml_resp->SSBMinistryCodes->addChild('SSBMinistryCode');
                $SSBMinistryCode->addChild('SSBMinistryID', $value['SSBMinistryID'] );
                $SSBMinistryCode->addChild('SSBMinistryDesc', str_replace("&", "&amp;", $value['SSBMinistry']) );
                //$SSBMinistryCode->addChild('SSMA_TimeStamp', $value['SSMA_TimeStamp'] );
            }
        }*/
        
        $xml_resp->addChild('TOECodes');
        if(is_array($row['TOECode'])){
            foreach($row['TOECode'] as $key => $value){
                $TOECode = $xml_resp->TOECodes->addChild('TOECode');
                $TOECode->addChild('TOEID', $value['TOEID'] );
                $TOECode->addChild('TOEDesc', str_replace("&", "&amp;", $value['TOEDesc']) );
            }
        }
        
        /*$xml_resp->addChild('MinistryCodeMaps');
        if(is_array($row['MinistryCodeMap'])){
            foreach($row['MinistryCodeMap'] as $key => $value){
                $MinistryCodeMap = $xml_resp->MinistryCodeMaps->addChild('MinistryCodeMap');
                $MinistryCodeMap->addChild('ID', $value['ID'] );
                $MinistryCodeMap->addChild('MinistryID', $value['MinistryID'] );
                $MinistryCodeMap->addChild('MinistryDesc', str_replace("&", "&amp;", $value['Ministry']) );
                $MinistryCodeMap->addChild('SSBMinistryID', $value['SSBMinistryID'] );
                $MinistryCodeMap->addChild('SSBMinistryDesc', str_replace("&", "&amp;", $value['SSBMinistry']) );
                //$MinistryCodeMap->addChild('SSMA_TimeStamp', $value['SSMA_TimeStamp'] );
            }
        }*/
        
        $xml_resp->addChild('PayStations');
        if(is_array($row['PayStations'])){
            foreach($row['PayStations'] as $key => $value){
                $PayStation = $xml_resp->PayStations->addChild('PayStation');
                $PayStation->addChild('MinistryID', $value['MinistryID'] );
                $PayStation->addChild('DeptCode', $value['DeptCode'] );
                $PayStation->addChild('PayStationCode', $value['PayStationCode'] );
                $PayStation->addChild('PayStationDesc', str_replace("&", "&amp;", $value['PayStationDesc']) );
                $PayStation->addChild('RegionCode', $value['RegionCode'] );
                $PayStation->addChild('ProvinceCode', $value['ProvinceCode'] );
                $PayStation->addChild('DistrictCode', $value['DistrictCode'] );
            }
        }

        $xml_resp->addChild('Countries');
        if(is_array($row['Countries'])){
            foreach($row['Countries'] as $key => $value){
                $Country = $xml_resp->Countries->addChild('Country');
                $Country->addChild('ISO', $value['ISO'] );
                $Country->addChild('CountryName', str_replace("&", "&amp;", $value['CountryName'] ));
            }
        }

        $xml_resp->addChild('InstitutionsTypes');
        if(is_array($row['InstitutionsTypes'])){
            foreach($row['InstitutionsTypes'] as $key => $value){
                $InstitutionType = $xml_resp->InstitutionsTypes->addChild('InstitutionType');
                $InstitutionType->addChild('ID', $value['InstitutionTypeId'] );
                $InstitutionType->addChild('Description', str_replace("&", "&amp;", $value['Description'] ));
            }
        }

        $xml_resp->addChild('AcadFields');
        if(is_array($row['AcadFields'])){
            foreach($row['AcadFields'] as $key => $value){
                $AcadField = $xml_resp->AcadFields->addChild('AcadField');
                $AcadField->addChild('ID', $value['FieldId'] );
                $AcadField->addChild('Description', str_replace("&", "&amp;", $value['Description'] ));
			}
        }

        $xml_resp->addChild('Qualifications');
        if(is_array($row['Qualifications'])){
            foreach($row['Qualifications'] as $key => $value){
                $Qualif = $xml_resp->Qualifications->addChild('Qualification');
                $Qualif->addChild('ID', $value['QualificationId'] );
                $Qualif->addChild('Description', str_replace("&", "&amp;", $value['Description'] ));
                $Qualif->addChild('FieldId', $value['FieldId'] );
            }
        }

        $xml_resp->addChild('UserAccessLevel', $row['User'][0]['AccessLevel']);
        
        return $xml_resp->asXML();
    }
    
    function updateXmlData(){
		$errorFound = false;
		
        //Set Auto Commit false - begin transaction
		$this->runStoredProc("BEGIN TRANSACTION");

		if($this->xml->EnumData->DocumentNumber){
            
            $sqlArr['tables'] = $this->odbc_db.'Repository';
            $sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $this->xml->EnumData->DocumentNumber)."'";
            
            $sqlArr['fields']['MinistryID'] = $this->xml->EnumData->StationID->MinistryId;
            $sqlArr['fields']['ECNo'] = $this->xml->EnumData->PersonnelID->ECNumber;
            $sqlArr['fields']['Department'] = $this->xml->EnumData->StationID->DepartmentId;
            $sqlArr['fields']['Station'] = $this->xml->EnumData->StationID->PayStationId;
            $sqlArr['fields']['Salutation'] = $this->shortenText($this->xml->EnumData->PersonnelID->Title, 10);
            $sqlArr['fields']['Surname'] = $this->xml->EnumData->PersonnelID->Surname;
            $sqlArr['fields']['FirstName'] = $this->xml->EnumData->PersonnelID->FirstName;
            $sqlArr['fields']['MiddleName'] = $this->xml->EnumData->PersonnelID->OtherNames;
            $sqlArr['fields']['NID'] = $this->xml->EnumData->PersonnelID->NationalId;
            if($this->xml->EnumData->PersonalInfo->DateBirth != ''){
                $sqlArr['fields']['DOB'] = $this->xml->EnumData->PersonalInfo->DateBirth;
            } else {
			    $sqlArr['fields']['DOB'] = null;
			}
            $sqlArr['fields']['City'] = $this->xml->EnumData->PersonalInfo->City;
            $sqlArr['fields']['Province'] = $this->xml->EnumData->PersonalInfo->Province;
            $sqlArr['fields']['Street'] = $this->xml->EnumData->ContactInfo->Street;
            $sqlArr['fields']['POBox'] = $this->xml->EnumData->ContactInfo->POBox;
            $sqlArr['fields']['Suburb'] = $this->xml->EnumData->ContactInfo->Suburb;
            $sqlArr['fields']['Area'] = $this->xml->EnumData->ContactInfo->Area;
            if($this->xml->EnumData->RecordOfEmployment->DateFirstAppt != ''){
                $sqlArr['fields']['DOFA'] = $this->xml->EnumData->RecordOfEmployment->DateFirstAppt;
            } else {
			    $sqlArr['fields']['DOFA'] = null;
			}
            if($this->xml->EnumData->RecordOfEmployment->DateApptCurr != ''){
                $sqlArr['fields']['DOAPG'] = $this->xml->EnumData->RecordOfEmployment->DateApptCurr;
            } else {
			    $sqlArr['fields']['DOAPG'] = null;
			}
            $sqlArr['fields']['Designation'] = $this->xml->EnumData->RecordOfEmployment->Designation;
            $sqlArr['fields']['Grade'] = $this->xml->EnumData->RecordOfEmployment->CurrentGrade;
            $sqlArr['fields']['SalaryCode'] = $this->xml->EnumData->RecordOfEmployment->SalaryCode;
            $sqlArr['fields']['TotalGrossSalary'] = $this->xml->EnumData->RecordOfEmployment->GrossMonthSalary;
            //NEW FIELD FOR LOGING PURPOSES
            $sqlArr['fields']['RowUpdatedDate'] = date('Y/m/d H:i:s');
            
            $testQuery = $this->updateData($sqlArr);
            if ($testQuery == false) {
                $errorFound = true;
                $errorMsg = odbc_errormsg($this->link);
            }
            
            unset($sqlArr);
            $sqlArr['tables'] = $this->odbc_db.'RepositoryExt';
            $sqlArr['fields'] = '[EUID]';
            $sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $this->xml->EnumData->DocumentNumber)."'";
            $rows['RepositoryExt'] = $this->getData($sqlArr);

            unset($sqlArr['fields']);
            $sqlArr['fields']['TransactionType'] = $this->xml->EnumData->TransactionType;
            $sqlArr['fields']['AttendanceID'] = $this->xml->EnumData->StationID->Attendance;
            if($this->xml->EnumData->StationID->EnumerationDate != ''){
                $sqlArr['fields']['EnumerationDate'] = $this->xml->EnumData->StationID->EnumerationDate;
            } else {
                $sqlArr['fields']['EnumerationDate'] = null;
            }
            $sqlArr['fields']['EnumerationName'] = $this->xml->EnumData->StationID->EnumerationName;
            $sqlArr['fields']['EnumerationSignature'] = $this->xml->EnumData->StationID->EnumerationSign;
            $sqlArr['fields']['PreviousName'] = $this->xml->EnumData->PersonnelID->PreviousName;
            $sqlArr['fields']['NSSAID'] = $this->xml->EnumData->PersonnelID->NSSAId;
            $sqlArr['fields']['BirthEntryNo'] = $this->xml->EnumData->PersonnelID->BirthEntryNo;
            $sqlArr['fields']['MedicalAidId'] = $this->xml->EnumData->PersonnelID->MedicalAidId;
            $sqlArr['fields']['AuthChangeName'] = $this->xml->EnumData->PersonnelID->Authorization;
            $sqlArr['fields']['DOBCheckbox'] = $this->xml->EnumData->PersonalInfo->DateBirthCheckbox;
            $sqlArr['fields']['POB'] = $this->xml->EnumData->PersonalInfo->PlaceBirth;
            $sqlArr['fields']['POBCheckbox'] = $this->xml->EnumData->PersonalInfo->PlaceBirthCheckbox;
            $sqlArr['fields']['CityCheckbox'] = $this->xml->EnumData->PersonalInfo->CityCheckbox;
            $sqlArr['fields']['District'] = $this->xml->EnumData->PersonalInfo->District;
            $sqlArr['fields']['DistrictCheckbox'] = $this->xml->EnumData->PersonalInfo->DistrictCheckbox;
            $sqlArr['fields']['ProvinceCheckbox'] = $this->xml->EnumData->PersonalInfo->ProvinceCheckbox;
            $sqlArr['fields']['Country'] = $this->xml->EnumData->PersonalInfo->Country;
            $sqlArr['fields']['CountryCheckbox'] = $this->xml->EnumData->PersonalInfo->CountryCheckbox;
            $sqlArr['fields']['Sex'] = $this->xml->EnumData->PersonalInfo->Sex;
            $sqlArr['fields']['SexCheckbox'] = $this->xml->EnumData->PersonalInfo->SexCheckbox;
            $sqlArr['fields']['MaritalStatus'] = $this->xml->EnumData->PersonalInfo->MaritalStatus;
            $sqlArr['fields']['MaritalStatusCheckbox'] = $this->xml->EnumData->PersonalInfo->MaritalStatusCheckbox;
            $sqlArr['fields']['Nationality'] = $this->xml->EnumData->PersonalInfo->Nationality;
            $sqlArr['fields']['NationalityCheckbox'] = $this->xml->EnumData->PersonalInfo->NationalityCheckbox;
            $sqlArr['fields']['DocUsedForVerif'] = $this->xml->EnumData->PersonalInfo->DocumentUsed;
            $sqlArr['fields']['HomePhone'] = $this->xml->EnumData->ContactInfo->HomePhone;
            $sqlArr['fields']['WorkPhone'] = $this->xml->EnumData->ContactInfo->WorkPhone;
            $sqlArr['fields']['MobilePhone'] = $this->xml->EnumData->ContactInfo->MobilePhone;
            $sqlArr['fields']['DOFACheckbox'] = $this->xml->EnumData->RecordOfEmployment->DateFirstApptCheckbox;
            if($this->xml->EnumData->RecordOfEmployment->ApptLetterDate != ''){
                $sqlArr['fields']['ApptLetterDate'] = $this->xml->EnumData->RecordOfEmployment->ApptLetterDate;
            } else {
			    $sqlArr['fields']['ApptLetterDate'] = null;
			}
            $sqlArr['fields']['ApptLetterDateCheckbox'] = $this->xml->EnumData->RecordOfEmployment->ApptLetterDateCheckbox;
            if($this->xml->EnumData->RecordOfEmployment->DateReappt != ''){
                $sqlArr['fields']['DateReappt'] = $this->xml->EnumData->RecordOfEmployment->DateReappt;
            } else {
			    $sqlArr['fields']['DateReappt'] = null;
			}
            $sqlArr['fields']['DateReapptCheckbox'] = $this->xml->EnumData->RecordOfEmployment->DateReapptCheckbox;
            $sqlArr['fields']['DOAPGCheckbox'] = $this->xml->EnumData->RecordOfEmployment->DateApptCurrCheckbox;
            $sqlArr['fields']['DesignationCheckbox'] = $this->xml->EnumData->RecordOfEmployment->DesignationCheckbox;
            $sqlArr['fields']['GradeCheckbox'] = $this->xml->EnumData->RecordOfEmployment->CurrentGradeCheckbox;
            $sqlArr['fields']['SalaryCodeCheckbox'] = $this->xml->EnumData->RecordOfEmployment->SalaryCodeCheckbox;
            $sqlArr['fields']['TotalGrossSalaryCheckbox'] = $this->xml->EnumData->RecordOfEmployment->GrossMonthSalaryCheckbox;
            if($this->xml->EnumData->RecordOfEmployment->MedicalClearFormDate != ''){
                $sqlArr['fields']['MedicalClearanceFormDate'] = $this->xml->EnumData->RecordOfEmployment->MedicalClearFormDate;
            } else {
			    $sqlArr['fields']['MedicalClearanceFormDate'] = null;
			}
            $sqlArr['fields']['MedicalClearanceFormDateCheckbox'] = $this->xml->EnumData->RecordOfEmployment->MedicalClearFormDateCheckbox;
            if($this->xml->EnumData->RecordOfEmployment->PoliceClearFormDate != ''){
                $sqlArr['fields']['PoliceClearanceFormDate'] = $this->xml->EnumData->RecordOfEmployment->PoliceClearFormDate;
            } else {
			    $sqlArr['fields']['PoliceClearanceFormDate'] = null;
			}
            $sqlArr['fields']['PoliceClearanceFormDateCheckbox'] = $this->xml->EnumData->RecordOfEmployment->PoliceClearFormDateCheckbox;
            if($this->xml->EnumData->RecordOfEmployment->AppointmentFormDate != ''){
                $sqlArr['fields']['ApptFormDate'] = $this->xml->EnumData->RecordOfEmployment->AppointmentFormDate;
            } else {
			    $sqlArr['fields']['ApptFormDate'] = null;
			}
            $sqlArr['fields']['ApptFormDateCheckbox'] = $this->xml->EnumData->RecordOfEmployment->ApptFormDateCheckbox;
            $sqlArr['fields']['PassportCopyBox'] = $this->xml->EnumData->RecordOfEmployment->Passport;
            $sqlArr['fields']['ApptLetterCopyBox'] = $this->xml->EnumData->RecordOfEmployment->AppointmentLetter;
            $sqlArr['fields']['MedicalClearFormCopyBox'] = $this->xml->EnumData->RecordOfEmployment->MedicalClearForm;
            $sqlArr['fields']['BirthCertifCopyBox'] = $this->xml->EnumData->RecordOfEmployment->BirthCertificate;
            $sqlArr['fields']['ApptFormCopyBox'] = $this->xml->EnumData->RecordOfEmployment->AppointmentForm;
            $sqlArr['fields']['PoliceClearFormCopyBox'] = $this->xml->EnumData->RecordOfEmployment->PoliceClearForm;
            $sqlArr['fields']['RespondentSign'] = $this->xml->EnumData->RespondentSign;
            $sqlArr['fields']['AuditorName'] = $this->xml->EnumData->AuditorName;
            $sqlArr['fields']['AuditorSign'] = $this->xml->EnumData->AuditorSign;
            $sqlArr['fields']['DataEnteryUserName'] = $this->xml->EnumData->DataEntryUserName;
            $sqlArr['fields']['DataEnteryUserSign'] = $this->xml->EnumData->DataEntryUserSign;
            $sqlArr['fields']['ObserverSign'] = $this->xml->EnumData->Notes->ObserverSign;
            $sqlArr['fields']['ObserverName'] = $this->xml->EnumData->Notes->ObserverName;
            if($this->xml->EnumData->Notes->DateObservations != ''){
                $sqlArr['fields']['DateObservations'] = $this->xml->EnumData->Notes->DateObservations;
            } else {
			    $sqlArr['fields']['DateObservations'] = null;
			}
            if($this->xml->EnumData->Notes->DateOpinionGiven != ''){
                $sqlArr['fields']['DateOpinionGiven'] = $this->xml->EnumData->Notes->DateOpinionGiven;
            } else {
			    $sqlArr['fields']['DateOpinionGiven'] = null;
			}
            $sqlArr['fields']['OpinionGiverSign'] = $this->xml->EnumData->Notes->OpinionGiverSign;
            $sqlArr['fields']['OpinionGiverName'] = $this->xml->EnumData->Notes->OpinionGiverName;
            $sqlArr['fields']['DataVerificationUserName'] = $this->xml->EnumData->DataVerificationUserName;
            $sqlArr['fields']['DataVerificationUserSign'] = $this->xml->EnumData->DataVerificationUserSign;
            $sqlArr['fields']['StatusCode'] = $this->xml->EnumData->StatusCode;
            $sqlArr['fields']['Rejected'] = $this->xml->EnumData->Rejected;
            $sqlArr['fields']['VerifierComment'] = $this->xml->EnumData->VerifierComment;

            //NEW FIELDS FOR CONTACT
            $sqlArr['fields']['Address'] = $this->xml->EnumData->ContactInfo->Address;
            $sqlArr['fields']['ContactCity'] = $this->xml->EnumData->ContactInfo->ContactCity;
            $sqlArr['fields']['ContactDistrict'] = $this->xml->EnumData->ContactInfo->ContactDistrict;
            $sqlArr['fields']['ContactProvince'] = $this->xml->EnumData->ContactInfo->ContactProvince;

            //NEW FIELD FOR LOGING PURPOSES
            $sqlArr['fields']['RowUpdatedDate'] = date('Y/m/d H:i:s');

            if(is_array($rows['RepositoryExt'])){
                $testQuery = $this->updateData($sqlArr);
				if ($testQuery == false) {
					$errorFound = true;
					$errorMsg = odbc_errormsg($this->link);
				}
            }
            else{
                $sqlArr['fields']['EUID'] = $this->xml->EnumData->DocumentNumber;
                $testQuery = $this->insertData($sqlArr);
				if ($testQuery == false) {
					$errorFound = true;
					$errorMsg = odbc_errormsg($this->link);
				}
            }

            unset($sqlArr);
			$sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $this->xml->EnumData->DocumentNumber)."'";
			$sqlArr['tables'] = $this->odbc_db.'AcademicQualif';
			$this->deleteData($sqlArr);
			unset($sqlArr);
            if($this->xml->EnumData->AcademicQual){
                foreach($this->xml->EnumData->AcademicQual as $AcademicQual){
                    $sqlArr['fields']['EUID'] = $this->xml->EnumData->DocumentNumber;
                    $sqlArr['fields']['ID'] = $AcademicQual->id;
                    if ($AcademicQual->InstitutionTypeId != '') {
						$sqlArr['fields']['InstitutionTypeId'] = $AcademicQual->InstitutionTypeId;
                    }
					$sqlArr['fields']['InstitutionName'] = $this->shortenText($AcademicQual->InstitutionName, 200);
                    if ($AcademicQual->FieldId != '') {
						$sqlArr['fields']['FieldId'] = $AcademicQual->FieldId;
                    }
					if ($AcademicQual->QualificationId != '') {
						$sqlArr['fields']['QualificationId'] = $AcademicQual->QualificationId;
                    }
					$sqlArr['fields']['YearCompleted'] = $AcademicQual->YearCompleted;
                    $sqlArr['fields']['DocumentsName'] = $AcademicQual->DocumentName;
                    $sqlArr['fields']['DocumentsBox'] = $AcademicQual->DocumentState;
                    $sqlArr['tables'] = $this->odbc_db.'AcademicQualif';
					$testQuery = $this->insertData($sqlArr);
					if ($testQuery == false) {
						$errorFound = true;
						$errorMsg = odbc_errormsg($this->link);
					}
                }
            }

            unset($sqlArr);
			$sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $this->xml->EnumData->DocumentNumber)."'";
			$sqlArr['tables'] = $this->odbc_db.'UniversityQualif';
			$this->deleteData($sqlArr);
			unset($sqlArr);
            if($this->xml->EnumData->UniversityQual){
                foreach($this->xml->EnumData->UniversityQual as $UniversityQual){
                    $sqlArr['fields']['EUID'] = $this->xml->EnumData->DocumentNumber;
                    $sqlArr['fields']['ID'] = $UniversityQual->id;
                    $sqlArr['fields']['InstitutionName'] = $this->shortenText($UniversityQual->InstitutionName, 200);
                    $sqlArr['fields']['Field'] = $this->shortenText($UniversityQual->Field, 100);
                    $sqlArr['fields']['qualification'] = $this->shortenText($UniversityQual->Qualification, 100);
                    $sqlArr['fields']['YearCompleted'] = $UniversityQual->YearCompleted;
                    $sqlArr['fields']['DocumentsName'] = $UniversityQual->DocumentName;
                    $sqlArr['fields']['DocumentsBox'] = $UniversityQual->DocumentState;
                    $sqlArr['tables'] = $this->odbc_db.'UniversityQualif';
                    $testQuery = $this->insertData($sqlArr);
					if ($testQuery == false) {
						$errorFound = true;
						$errorMsg = odbc_errormsg($this->link);
					}
                }
            }
            
            unset($sqlArr);
			$sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $this->xml->EnumData->DocumentNumber)."'";
            $sqlArr['tables'] = $this->odbc_db.'ProfQualif';
            $this->deleteData($sqlArr);
            unset($sqlArr);
            if($this->xml->EnumData->ProfQual){
                foreach($this->xml->EnumData->ProfQual as $ProfQual){
                    $sqlArr['fields']['EUID'] = $this->xml->EnumData->DocumentNumber;
                    $sqlArr['fields']['ID'] = $ProfQual->id;
                    $sqlArr['fields']['Field'] = $this->shortenText($ProfQual->Field, 100);
                    $sqlArr['fields']['qualification'] = $this->shortenText($ProfQual->Qualification, 100);
                    $sqlArr['fields']['InstitutionName'] = $this->shortenText($ProfQual->InstitutionName, 200);
                    $sqlArr['fields']['YearCompleted'] = $ProfQual->YearCompleted;
                    $sqlArr['fields']['DocumentsName'] = $ProfQual->DocumentName;
                    $sqlArr['fields']['DocumentsBox'] = $ProfQual->DocumentState;
                    $sqlArr['tables'] = $this->odbc_db.'ProfQualif';
					$testQuery = $this->insertData($sqlArr);
					if ($testQuery == false) {
						$errorFound = true;
						$errorMsg = odbc_errormsg($this->link);
					}
                }
            }
            
            unset($sqlArr);
			$sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $this->xml->EnumData->DocumentNumber)."'";
			$sqlArr['tables'] = $this->odbc_db.'Training';
			$this->deleteData($sqlArr);
			unset($sqlArr);
            if($this->xml->EnumData->InServiceTraining){
                foreach($this->xml->EnumData->InServiceTraining as $InServiceTraining){
                    $sqlArr['fields']['EUID'] = $this->xml->EnumData->DocumentNumber;
                    $sqlArr['fields']['ID'] = $InServiceTraining->id;
                    $sqlArr['fields']['Course'] = $this->shortenText($InServiceTraining->TrainingCourse, 100);
                    $sqlArr['fields']['Institution'] = $this->shortenText($InServiceTraining->Institution, 100);
                    $sqlArr['fields']['YearCompleted'] = $InServiceTraining->YearCompleted;
                    $sqlArr['fields']['DocumentsName'] = $InServiceTraining->DocumentName;
                    $sqlArr['fields']['DocumentsBox'] = $InServiceTraining->DocumentState;
                    $sqlArr['tables'] = $this->odbc_db.'Training';
                    $testQuery = $this->insertData($sqlArr);
					if ($testQuery == false) {
						$errorFound = true;
						$errorMsg = odbc_errormsg($this->link);
					}
                }
            }
            
            unset($sqlArr);
			$sqlArr['where'] = "[EUID] = '".str_replace("'", "''", $this->xml->EnumData->DocumentNumber)."'";
			$sqlArr['tables'] = $this->odbc_db.'Notes';
			$this->deleteData($sqlArr);
			unset($sqlArr);
            if($this->xml->EnumData->Notes->Note){
                foreach($this->xml->EnumData->Notes->Note as $Note){
                    $sqlArr['fields']['EUID'] = $this->xml->EnumData->DocumentNumber;
                    $sqlArr['fields']['NoteRef'] = $Note->NoteRef;
                    $sqlArr['fields']['DocumentSection'] = $Note->RelatedSection;
                    $sqlArr['fields']['Observation'] = $Note->Observation;
                    $sqlArr['fields']['Opinion'] = $Note->Opinion;
                    $sqlArr['tables'] = $this->odbc_db.'Notes';
                    $testQuery = $this->insertData($sqlArr);
					if ($testQuery == false) {
						$errorFound = true;
						$errorMsg = odbc_errormsg($this->link);
					}
                }
            }
        }
		
		//Commit the work done if everything went fine, else we roll back
		if ($errorFound == true) {
			odbc_rollback($this->link);
			$this->runStoredProc("ROLLBACK");
			return $errorMsg;
		} else {
			odbc_commit($this->link);
			$this->runStoredProc("COMMIT");
			return "1";
		}
    }
    
    function getData($sqlArr){
        
        if ($this->link) {
            $sql = 'SELECT '.($sqlArr['fields']?$sqlArr['fields']:'*').' FROM '.$sqlArr['tables']
				.' WHERE '.($sqlArr['where']?$sqlArr['where']:'1=1');
            $prepare = odbc_prepare($this->link, $sql);
            
            if(odbc_execute($prepare)) {
                $res = odbc_exec($this->link, $sql);
                
                while(odbc_fetch_row($res)){
                    $i = 1;
                    $max = odbc_num_fields($res);
                    while($i <= $max){
                        $row[odbc_field_name($res,$i)] = odbc_result($res,$i);
                        $i++;
                    }
                    if (isset($row)) {
						$rows[] = $row;
						unset($row);
					}
                }
            }
        }
        if (isset($rows)) {
			return $rows;
		}
    }
    
    function updateData($sqlArr){
	    //Mettons auto

        // Arrange les champs � updater
        if(is_array($sqlArr['fields'])){
            foreach( $sqlArr['fields'] as $column => $value){
                if ($value != null) {
				    $temp[] = "[".$column."] = '".str_replace("'", "''", $value)."'";
				} else {
				    $temp[] = "[".$column."] = NULL";
				}
            }
            $sqlArr['fields'] = implode(', ',$temp);
        }
        
        if ($this->link) {
            $sql = 'UPDATE '.$sqlArr['tables'].' SET '.$sqlArr['fields'].' WHERE '.$sqlArr['where'];
            //echo '<br/><br/>'.$sql.'<br/><br/>';
            $res = odbc_exec($this->link, $sql);
        }
        return $res;
    }
    
    function insertData($sqlArr){
        
        // Arrange les champs � updater
        if(is_array($sqlArr['fields'])){
            foreach( $sqlArr['fields'] as $column => $value){
                $columns[] = '['.$column.']';
                if ($value != null) {
					$values[] = "'".str_replace("'", "''", $value)."'";
				} else {
					$values[] = "NULL";
				}
            }
            $sqlArr['fields'] = '('.implode(', ',$columns).') VALUES ('.implode(', ',$values).')';
        }
        
        if ($this->link) {
            $sql = 'INSERT '.$sqlArr['tables'].' '.$sqlArr['fields'];
            //echo '<br/><br/>'.$sql.'<br/><br/>';
            $res = odbc_exec($this->link, $sql);
        }
        return $res;
    }
    
    function deleteData($sqlArr){
        
        if ($this->link) {
            $sql = 'DELETE FROM '.$sqlArr['tables'].' WHERE '.$sqlArr['where'];
            $res = odbc_exec($this->link, $sql);
        }
        return $res;
    }

    function runSQL($sql){

        $val;
 
        if($this->link) {
            $res = odbc_exec($this->link, $sql);
            while(odbc_fetch_row($res)){
                $i = 1;
                $max = odbc_num_fields($res);
                while($i <= $max){
                    $row[odbc_field_name($res,$i)] = odbc_result($res,$i);
                    $i++;
                }
                if (isset($row)) {
					$rows[] = $row;
					unset($row);
				}
            }
        }
		if (isset($rows)) {
			return $rows;
		}
    }
	
	function runStoredProc($sql){

        if($this->link) {
            odbc_exec($this->link, $sql);
        }
    }
    
    function identify(){
        
        $identified = false;
        
        $sqlArr['tables'] = $this->odbc_db.'Users';
        $sqlArr['fields'] = '[Password]';
        $sqlArr['where'] = "[Username]='".str_replace("'", "''", $this->xml->SecurityContext->UserName)."'";
        $row['Users'] = $this->getData($sqlArr);
        
        $temp = $this->xml->SecurityContext->UserName . ':' . $row['Users'][0]['Password'];
        $temp = md5($temp);
        $password = md5($this->hashStr . $temp);
        
        if($this->xml->SecurityContext->UserPasswordMD5Hash == $password){
            $identified = true;
        }
        
        return $identified;
    }
    
    function accessLevel(){ // d�veloppement futur
        return true;
    }
	
	function shortenText($text, $length) {
		$text = $text." ";
        $text = substr($text,0,$length);
        $text = substr($text,0,strrpos($text,' '));
        return $text;
    }

    
    function getErrorResponse($code, $description){
        $str_resp = '<?xml version="1.0" encoding="utf-8"?>
                        <RequestProcessingError xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
						</RequestProcessingError>';
        
        $xml_resp = new SimpleXMLElement($str_resp);
        
        $xml_resp->addChild('ErrorCode', $code);
        $xml_resp->addChild('ErrorDescription', $description);
        
        return $xml_resp->asXML();
        
    }
    
}

?>